<?
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: pre-check=0, post-check=0, max-age=0");
header("Pragma: no-cache");
header("Expires: 0");
header("Content-Transfer-Encoding: none");
header("Content-Type: application/vnd.ms-excel;");
header("Content-type: application/x-msexcel");
header("Content-Disposition: attachment; filename=Rel_Contas_Receber_".date('d-m-Y').".xls")
?>
<style>

    .image{
        float: left;
    }

    .nomeRel{
        width: 50%;
        margin-left: 150px;
        font-size: 30px;
        padding-top: 40px;
        height: 50px
    }

    #table-bordered{

        width: 100%

    }

    th{
        background-color: #49716A;
        color: white;
    }

    td{
        text-align: center;
        color: #333;
    }

</style>
<body>

            <? //print_r($this->variaveis) ?>
            <!--<div style="width: 100%">
                <img alt="foto" class="image" width="100" height="100" src="/theme/default/imgs/logo.jpg"/>
                <div class="nomeRel"><u>Relatorio de Atendimento</u></div>
            </div>-->
            <? $periodoInicial = $this->variaveis["dt_inicioMes"]."/".$this->variaveis["dt_inicioAno"]; ?>
            <? $periodoFinal = $this->variaveis["dt_fimMes"]."/".$this->variaveis["dt_fimAno"];
                if ($periodoInicial == $periodoFinal){
                    $resultado = $periodoInicial = $this->variaveis["dt_inicioMes"]."/".$this->variaveis["dt_inicioAno"];
                } else {
                    $resultado = $this->variaveis["dt_inicioMes"]."/".$this->variaveis["dt_inicioAno"].utf8_decode(" à ").$this->variaveis["dt_fimMes"]."/".$this->variaveis["dt_fimAno"];
                }

            ?>

            <table id="table-bordered" border="1" align="center" >
                    <tr>
                        <td colspan="2" style="background-color: #49716A; color: white;">
                            <h2><?= utf8_decode("Período Analisado - ").$resultado; ?></h2>
                        </td>
                    </tr>

            <!-- inicio da tabela de Atendimento -->

                <tr height="20">
                    <tr><td style="background-color: #DEEABB; color: #333" colspan="2">Faturamento Atendimentos</td></tr>

                    <tr>
                        <td style="background-color: #49716A; color: white;">Quantidade de atendimentos</td>
                        <td style="background-color: #49716A; color: white;">Bruto de Rendimentos</td>
                    </tr>

                     <? foreach ($this->result as $table) { ?>
                    <tr>
                        <td><?= $table["atendimentos"]." atendimentos prestados";?></td>
                        <td><?= "R$ ".number_format($table["valor"]*$table["pavor"], 2);?></td>

                    </tr>
                        <? }

                    ?>
                </tr>
                    <!-- inicio da tabela de despesa -->
                    <tr height="20">
                    <tr ><td style="background-color: #DEEABB; color: #333" colspan="2"><?= utf8_decode("Despesas do período"); ?></td></tr>

                    <tr>
                        <td style="background-color: #49716A; color: white;">Quantidade de despesas</td>
                        <td style="background-color: #49716A; color: white;">Bruto de Dividendos</td>
                    </tr>
                    <? foreach ($this->result2 as $table2) { ?>
                    <tr>
                        <td><?= $table2["pagamentos"] ;?></td>
                        <td><?= "R$ ".number_format($table2["valor"], 2) ;?></td>
                    </tr>
                        <? } ?>

                    </tr>
                    <!-- inicio da tabela de Faturamento -->
                    <tr height="20">
                    <tr><td colspan="2" style="background-color: #DEEABB; color: #333"><?= utf8_decode("Lucro líquido"); ?></td></tr>

                    <tr>
                        <td colspan="2" style="background-color: #49716A; color: white;">Faturamento</td>
                    </tr>
                    <tr>
                        <? $resultado = ($table["valor"]*$table["pavor"]) - $table2["valor"]; ?>
                        <? if($resultado >= 0){ ?>
                            <td colspan="2" style="color: green"><?= "R$ ".number_format($resultado, 2); ?></td>
                        <? }else{ ?>
                            <td colspan="2" style="color: red"><?= "R$ ".number_format($resultado, 2); ?></td>
                        <? } ?>

                     </tr>
                 </table>

</body>
